package com.zf.controller;


import com.zf.pojo.form;
import com.zf.pojo.optionalSeat;
import com.zf.pojo.person;
import com.zf.service.personService;
import com.zf.service.seatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class seatController {

    @Autowired
    seatService seatService;
    @Autowired
    personService personService;

    static int index=20;

    @ResponseBody
    @PostMapping("seat/{flightNumber}/{seatLocation}")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<optionalSeat> optionalSeats(@PathVariable String flightNumber, @PathVariable String seatLocation){
        return    seatService.optional(flightNumber, seatLocation);
    }



    @ResponseBody
    @PostMapping("/send")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public void  send(@RequestBody form  form){

        person person = new person(form.getName(), form.getFlightNumber(), form.getSeatId(), form.getSeatLocation());
       /* ++index;*/
        personService.addPerson(person);
        seatService.delete(form.getSeatId());

    }



}
